package com.kavian.test.search.test;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.filters.AndFilter;
import org.htmlparser.filters.HasAttributeFilter;
import org.htmlparser.filters.NodeClassFilter;
import org.htmlparser.tags.LinkTag;
import org.htmlparser.util.NodeList;

public class MaxMaya {

	public static void main(String[] args) throws Exception {
		HttpClient httpclient = new DefaultHttpClient();

		HttpGet httpget = new HttpGet("http://maxmaya.com");
		HttpResponse response = httpclient.execute(httpget);
		HttpEntity entity = response.getEntity();

		String content = EntityUtils.toString(entity, "GB2312");

		Parser parser = Parser.createParser(content, "utf-8");

		NodeFilter subject = new AndFilter(new NodeClassFilter(
				org.htmlparser.tags.TableColumn.class), new HasAttributeFilter(
				"class", "subject"));
		NodeList lis = parser.extractAllNodesThatMatch(subject);
		
		for (int i = 0; i < lis.size(); i++) {
			String str = lis.toHtml();
			System.out.println(str);
		}

//		System.out.println(content);

	}
}
